/**
 * Description: RegisterLateDAOImpl.java
 * Copyright (c) 2008-2009  Neo. 
 * All Rights Reserved.
 * @version 1.0  Apr 4, 2009 1:16:16 PM 李萌（neolimeng@gmail.com）created
 */
package org.paradise.dms.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.paradise.dms.pojo.RegisterLate;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.stereotype.Service;

import com.dheaven.framework.dao.BaseHibernateDao;
import com.dheaven.framework.dao.DaoException;

/**
 * Description: Copyright (c) 2008-2009 Neo. All Rights Reserved.
 * 
 * @version 1.0 Apr 4, 2009 1:16:16 PM 李萌（neolimeng@gmail.com）created
 */
@Service
public class RegisterLateDAOImpl extends BaseHibernateDao<RegisterLate> {
	public void insertRegisterLate(RegisterLate rl) throws DaoException {
		this.create(rl);
	}

	public void updateRegisterLate(RegisterLate rl) throws DaoException {
		this.update(rl);
	}

	public void deleteRegisterLate(int rlid) {
		SQLQuery sqlQuery = (SQLQuery) this
				.getSession()
				.createSQLQuery(
						"update registerlate set registerlateind=0 where registerlateid=?")
				.setInteger(0, rlid);
		sqlQuery.executeUpdate();
	}

	public RegisterLate getRegisterLate(int rlid) throws DaoException {
		return (RegisterLate) this
				.find(
						"from RegisterLate where registerlateid=? and registerlateind=1",
						new Object[] { rlid }).get(0);
	}

	@SuppressWarnings("unchecked")
	public List<RegisterLate> getAllRegisterLate() {
		return (List<RegisterLate>) this
				.find("from RegisterLate where registerlateind=1");
	}

	public int getAllRows() {
		return this.find("from RegisterLate where registerlateind=1").size();
	}

	@SuppressWarnings("unchecked")
	public List<RegisterLate> listAllRegisterLate(int pageSize, int startRow) {
		final int pageSize1 = pageSize;
		final int startRow1 = startRow;
		return this.getHibernateTemplate().executeFind(new HibernateCallback() {
			public List doInHibernate(Session session)
					throws HibernateException, SQLException {
				Query query = session
						.createQuery("from RegisterLate where registerlateind=1");
				query.setFirstResult(startRow1);
				query.setMaxResults(pageSize1);
				return query.list();
			}
		});
	}
}
